<?php  echo $this->session->flash();?>
<div class="file">
	<?php echo $this->Form->create("SystemModule",array("method"=>"POST","name"=>"frm" ,"id" =>"frm1"));?>
     <table width="100%" border="0" cellspacing="1" cellpadding="2" bgcolor="#686550">
         <tr>
             <td colspan="5" style="text-align: right; background: #ffffff;"> | <strong>
                <?php 
                    echo $roleName.' &raquo; '. $main_module_name_to_display. ' &raquo; '.$module_name_to_display."&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
                ?>
                 </strong>
            </td>
        </tr>
        <tr class="heading">
	 <td width="5%" valign="top" bgcolor="#708089"><?php echo __('S.NO')?></td>
         <td width="5%" bgcolor="#708089"><input  type="checkbox" name='checkall' id="checkall" onclick="Users.checkAllSystemmodule();" ></td>
           <td valign="top" bgcolor="#708089"><?php  echo __('MODULE_NAME');?></td>
          <td valign="top" bgcolor="#708089"><?php  echo __('PERMISSION');?></td>
           <td valign="top" bgcolor="#708089"><?php  echo __('CREATED');?></td>
        </tr>
  
        <?php
        if(isset($permissionArray) && ($permissionArray!="")){
          $i=0;
          foreach($permissionArray as $arrayDetail){
           
            
            if(isset($arrayDetail['SystemModulePermission'][0]['permission']) && $arrayDetail['SystemModulePermission'][0]['permission'] == 1){
                            $statusCls = "active-status-img";
			    $statusMsg = "deactivate";
			    	   
                        }else{
                            $statusCls = "forbidden-status-img";
			    $statusMsg = "activate";
			    
                        }
          ?>
              <tr>
                  <td bgcolor="#FFFFFF"><?php echo $i+1?></td>
		  <?php if(isset($arrayDetail['SystemModulePermission'][0]['permission']) &&  $arrayDetail['SystemModulePermission'][0]['permission']==1){
                            $url= '/users/updatepermission/'.$moduleName.'/denyperm/'.$arrayDetail['SystemModulePermission'][0]['id'].'/'.$arrayDetail['SystemModulePermission'][0]['role_id'];          
                            $image = 'saas-images/status.gif';
                            $alertMessage=__('SURE_DENIED',true);
			    $alt = "Deny Permission";
			    $systemModulePermId =  "deny/".$arrayDetail['SystemModulePermission'][0]['id'].'/'.$arrayDetail['SystemModulePermission'][0]['role_id']; 
			    
			}
                        elseif(isset($arrayDetail['SystemModulePermission'][0]['permission']) &&  $arrayDetail['SystemModulePermission'][0]['permission']==0){
                             $url= '/users/updatepermission/'.$moduleName.'/allowperm/'.$arrayDetail['SystemModulePermission'][0]['id'].'/'.$arrayDetail['SystemModulePermission'][0]['role_id'];
                            $image = 'saas-images/forbidden.gif';
                            $alertMessage=__('SURE_GRANTED',true);
			    $alt = "Grant Permission";
			    $systemModulePermId =  "allow/".$arrayDetail['SystemModulePermission'][0]['id'].'/'.$arrayDetail['SystemModulePermission'][0]['role_id']; 
                        }
                        else{
                           $url= '/users/updatepermission/'.$moduleName.'/insertallowperm/'.$arrayDetail['SystemModule']['id'].'/'.$roleId;
                            $image = 'saas-images/forbidden.gif';
                            $alertMessage=__('SURE_GRANTED',true);
			    $alt = "Grant Permission";
			    $systemModulePermId =  'insertallowperm/'.$arrayDetail['SystemModule']['id'].'/'.$roleId; 
			    
			}			
		  
		  ?>
		  <td bgcolor="#FFFFFF">
		  <?php echo $this->Form->checkbox('SystemModule.system_module_multiple_ids', array('hiddenField' => false,'class'=>'text-input chk-bx','name'=>'systemids[]','value'=>$systemModulePermId,'label'=>false,'onclick'=>"Users.uncheckSystemModuleId();"));  ?></td>
                  <td bgcolor="#FFFFFF"><?php echo ucfirst($arrayDetail['SystemModule']['module'])?></td>
                <td bgcolor="#FFFFFF" align="center"><?php
			//echo $this->Js->link($this->html->image($image, array('border' => 0, 'alt' => $alt, 'title' => $alt)), $url, array('update' => '#permissionListDiv', 'escape' => false, 'confirm' => $alertMessage));
			echo $this->Js->link($this->html->image($image, array('border' => 0, 'alt' => $alt, 'title' => $alt)), $url, array('update' => '#permissionListDiv', 'escape' => false)); 
			?></td>
                    <td bgcolor="#FFFFFF"><?php if(isset($arrayDetail['SystemModulePermission'][0]['created'])) {
			echo date("M-d-Y", strtotime($arrayDetail['SystemModulePermission'][0]['created']));
                        }else{ echo "NA";
                        }?></td>
              </tr>  
          <?php
          $i++;
          }
        }
         if(empty($permissionArray)){
        ?>
        <tr>
            <td bgcolor="#FFFFFF" colspan="8" align="center">
        <?php
               echo __("NO_RECORD_MESSAGE",true);
            ?>
            </td>
        </tr>
        <?php
         }
         else{?>
           
    </table>
     <table>
	  
	     <tr>
		<td bgcolor="#FFFFFF">
			<div class="actionbtns">
                            <?php echo $this->Form->submit( __('ALLOW', true) , array('class' => 'button', 'div' => false,'alt'=>__('ALLOW', true),'title'=>__('ALLOW', true) ,'style'=>"width:80px;", 'onClick'=>'Users.confirmActionSytemModulePermission("allow");return false;'));?><div class="buttonEnding"></div>
                        </div>
		</td>
		<td>&nbsp;</td>
		<td bgcolor="#FFFFFF">	
                    <div class="actionbtns">
			<?php echo $this->Form->submit( __('DENY', true) , array('class' => 'button', 'div' => false,'alt'=>__('DENY', true),'title'=>__('DENY', true) ,'style'=>"width:80px;", 'onClick'=>'Users.confirmActionSytemModulePermission("deny");return false;'));?><div class="buttonEnding"></div>
                    </div>
	    	</td>
	     </tr>
	    
           <?php } ?>
     </table>
     <?php echo $this->Form->end();?>
</div>
<?php echo $this->Js->writeBuffer(); // Write cached scripts?>